package cn.myfirefly.moming.house.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.myfirefly.moming.house.dao.mapper.SpfTradeTrackFormMapper;
import cn.myfirefly.moming.house.entity.SpfTradeTrackForm;
import cn.myfirefly.moming.house.model.SpfTradeContractDto;
import cn.myfirefly.moming.house.model.SpfTradeTrackFormDto;
import cn.myfirefly.moming.house.model.SpfTradeTrackFormFilterDto;
import cn.myfirefly.core.BaseDao;
import cn.myfirefly.core.model.PageResultDto;
import cn.myfirefly.core.mybatis.BjuiDataGridFilter;
import cn.myfirefly.core.mybatis.BjuiDataGridSqlHelper;
import cn.myfirefly.utils.StrUtil;

@Repository
public class SpfTradeTrackFormDao extends BaseDao<SpfTradeTrackForm> {
	
	@Autowired
	private SpfTradeTrackFormMapper spfTradeTrackFormMapper;
	
	public PageResultDto<SpfTradeTrackFormDto> getList(SpfTradeTrackFormFilterDto dto) {
		PageResultDto<SpfTradeTrackFormDto> resultDto = new PageResultDto<>();
		//参数处理
		Map<String, Object> paraMap = new HashMap<>();
		BjuiDataGridFilter bjuiDataGridFilter = BjuiDataGridSqlHelper.addFilter(dto);
		paraMap.putAll(bjuiDataGridFilter.getParam());
		//分页处理
		Page<SpfTradeTrackFormDto> page = PageHelper.startPage(dto.getPageCurrent(), dto.getPageSize(), true);
		List<SpfTradeTrackFormDto> list = spfTradeTrackFormMapper.getList(paraMap);
		resultDto.setPageCurrent(dto.getPageCurrent());
		resultDto.setTotal((int)page.getTotal());
		resultDto.setList(list);
		return resultDto;
	}
	
	public PageResultDto<SpfTradeTrackFormDto> getToBeAuditedList(SpfTradeTrackFormFilterDto dto) {
		PageResultDto<SpfTradeTrackFormDto> resultDto = new PageResultDto<>();
		//参数处理
		Map<String, Object> paraMap = new HashMap<>();
		BjuiDataGridFilter bjuiDataGridFilter = BjuiDataGridSqlHelper.addFilter(dto);
		paraMap.putAll(bjuiDataGridFilter.getParam());
		//分页处理
		Page<SpfTradeTrackFormDto> page = PageHelper.startPage(dto.getPageCurrent(), dto.getPageSize(), true);
		List<SpfTradeTrackFormDto> list = spfTradeTrackFormMapper.getToBeAuditedList(paraMap);
		resultDto.setPageCurrent(dto.getPageCurrent());
		resultDto.setTotal((int)page.getTotal());
		resultDto.setList(list);
		return resultDto;
	}
	
	public PageResultDto<SpfTradeTrackFormDto> getList(SpfTradeContractDto dto) {
		PageResultDto<SpfTradeTrackFormDto> resultDto = new PageResultDto<>();
		//参数处理
		String tradeAddress = null;
		if (StrUtil.notBlank(dto.getTradeAddress())) {
			tradeAddress = "%" + dto.getTradeAddress() + "%";
		}
		String tradePerson = null;
		if (StrUtil.notBlank(dto.getTradePerson())) {
			tradePerson = "%" + dto.getTradePerson() + "%";
		}
		//分页处理
		Page<SpfTradeTrackFormDto> page = PageHelper.startPage(dto.getPageCurrent(), dto.getPageSize(), true);
		List<SpfTradeTrackFormDto> list = spfTradeTrackFormMapper.getListBy(tradeAddress, tradePerson);
		resultDto.setPageCurrent(dto.getPageCurrent());
		resultDto.setTotal((int)page.getTotal());
		resultDto.setList(list);
		return resultDto;
	}
}
